<?php

/**
 * This is the model class for table "inspector".
 *
 * The followings are the available columns in table 'inspector':
 * @property integer $id
 * @property string $inspector_lastname
 * @property string $i_firstname
 * @property string $i_middlename
 * @property string $position
 * @property integer $contact_no
 * @property integer $telephone_no
 * @property integer $inspection_id
 *
 * The followings are the available model relations:
 * @property Inspection $inspection
 */
class Inspector extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Inspector the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'inspector';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('inspection_id', 'required'),
			array('contact_no, telephone_no, inspection_id', 'numerical', 'integerOnly'=>true),
			array('inspector_lastname, i_firstname, i_middlename', 'length', 'max'=>45),
			array('position', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, inspector_lastname, i_firstname, i_middlename, position, contact_no, telephone_no, inspection_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'inspection' => array(self::BELONGS_TO, 'Inspection', 'inspection_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'inspector_lastname' => 'Inspector Lastname',
			'i_firstname' => 'I Firstname',
			'i_middlename' => 'I Middlename',
			'position' => 'Position',
			'contact_no' => 'Contact No',
			'telephone_no' => 'Telephone No',
			'inspection_id' => 'Inspection',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('inspector_lastname',$this->inspector_lastname,true);
		$criteria->compare('i_firstname',$this->i_firstname,true);
		$criteria->compare('i_middlename',$this->i_middlename,true);
		$criteria->compare('position',$this->position,true);
		$criteria->compare('contact_no',$this->contact_no);
		$criteria->compare('telephone_no',$this->telephone_no);
		$criteria->compare('inspection_id',$this->inspection_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}